﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace WEALTH.Manager.Customer
{
    public partial class AddLeftMenu : BasePage
    {
        private ExcuteDao dao = new ExcuteDao();

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 添加菜单信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                //验证页面数据
                if (!CheckData())
                {
                    return;
                }

                if (dao.Insert_LeftMenu(
                    SpecialCharHandler.HtmlEncode(txtLeftMenuName.Text),
                    SpecialCharHandler.HtmlEncode(txtLeftMenuType.Text),
                    getCurrentUser().UserID) == 1)
                {
                    ReturnList("LeftMenuList.aspx", "添加客户端菜单成功！");

                }
                else
                {
                    ShowMsg("添加客户端菜单失败，请确认！", 1);
                }
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message.ToString(), 1);
            }

        }
        /// <summary>
        /// 验证页面内容
        /// </summary>
        /// <returns></returns>
        private bool CheckData()
        {
            if (string.IsNullOrEmpty(txtLeftMenuName.Text.TrimEnd()))
            {
                ShowMsg("请输入菜单名称！", 1);
                txtLeftMenuName.Focus();
                return false;
            }
            if (string.IsNullOrEmpty(txtLeftMenuType.Text.TrimEnd()))
            {
                ShowMsg("请输入类型名称！", 1);
                txtLeftMenuType.Focus();
                return false;
            }

            DataTable dt = dao.Get_LeftMenu();

            DataRow[] dr = dt.Select("MenuName = '" + SpecialCharHandler.HtmlEncode(txtLeftMenuName.Text) + "'");

            if (dr.Length > 0)
            {
                ShowMsg("菜单名称已经存在，请确认！", 1);
                txtLeftMenuName.Focus();
                return false;
            }
            return true;
        }
    }
}